#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN DATA ABSTRACTION LAYER version 1

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Using directives
using System;
using Thn.Application;
#endregion

namespace Thn.Data.Persistence
{
    /// <summary>
    /// Represents a modification of a persistent object's property
    /// </summary>
    public class UpdatePropertyCommand : PersistentObjectCommand
    {
        #region Property Name
        private string mPropertyName = string.Empty;
        /// <summary>
        /// Gets/Sets name of the property that has been changed
        /// </summary>
        [Savable]
        public string PropertyName
        {
            get { return mPropertyName; }
            set { mPropertyName = value; }
        }
        #endregion

        #region Old Value
        private object mOldValue;
        /// <summary>
        /// Gets/Sets previous value of the property
        /// </summary>
        public object OldValue
        {
            get { return mOldValue; }
            set { mOldValue = value; }
        }
        #endregion

        #region New Value
        private object mNewValue = null;
        /// <summary>
        /// Gets/Sets new value of the property
        /// </summary>
        [Savable]
        public object NewValue
        {
            get { return mNewValue; }
            set { mNewValue = value; }
        }
        #endregion

        #region To String
        /// <summary>
        /// Converts this command to string
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("Update Object Command - Property: {0} - Old: {1} - New: {2} - {3}", mPropertyName, mOldValue, mNewValue, base.ToString());
        }
        #endregion
		
        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public UpdatePropertyCommand()
        { }

        /// <summary>
        /// Create new instance
        /// </summary>
        /// <param name="target">The object this command is involved with</param>
        /// <param name="propertyName">Name of the property that has been changed</param>
        /// <param name="oldValue">Previous value of the property</param>
        /// <param name="newValue">New value of the property</param>
        public UpdatePropertyCommand(IPersistentObject target, string propertyName, object oldValue, object newValue)
            : base(target)
        {
            mPropertyName = propertyName;
            mOldValue = oldValue;
            mNewValue = newValue;
        }
        #endregion
    }
}
